import request from "@/utils/request";

const AUTH_BASE_URL = "/user";

const AuthAPI = {
  /** login */
  login(data: LoginData) {
    return request<any, LoginResult>({
      url: `${AUTH_BASE_URL}/login`,
      method: "post",
      data: {
        userEmail: data.userEmail,
        userPassword: data.userPassword,
        userId: data.userId,
      },
      headers: {
        "Content-Type": "application/json",
      },
    });
  },

  /** refresh token */
  refreshToken(refreshToken: string) {
    return request<any, LoginResult>({
      url: `${AUTH_BASE_URL}/refreshToken`,
      method: "post",
      data: { refreshToken: refreshToken },
      headers: {
        Authorization: "no-auth",
      },
    });
  },

  /** logout */
  logout() {
    return request({
      url: `${AUTH_BASE_URL}/logout`,
      method: "get",
    });
  },
};

export default AuthAPI;

export interface LoginData {
  userEmail: string;
  userPassword: string;
  userId: number | string | undefined;
}

/** login response */
export interface LoginResult {
  accessToken: string;
  refreshToken: string;
  tokenType: string;
  expiresIn: number;
}
